var express = require('express');
var router = express.Router();
var mogoUnit=require('../servicebus/mongodbcurd') //引入mongodb 数据库操作函数

var multipart = require('connect-multiparty'); //处理post请求 数据
var multipartMiddleware = multipart();

var baseUrl='mongodb://localhost:27017'  //数据库地址
var database='sever' //服务集合
var curd='boke' //表
// console.log(mogoUnit)

/* GET users listing.  参数以url?param=value的形式传递：*/
router.get('/ids', function(req, res, next) {
  // res.render('index',{title:'respond with a resource'});
  console.log(req.query)
  res.send(req.query)
  // res.status(200).end()
});

router.post('/saveAtrticle',multipartMiddleware,(req,res)=>{
  // console.log(req,res)
  const id=req.body.id
  console.log(req.body)
  const userContent={
    content:req.body.content,
    title:req.body.title,
    name:req.body.name,
  }
  if(id){ //有id就是修改
    
  }else{ //没有id就是新增
    mogoUnit.inserts(baseUrl,database,curd,userContent)
  }
  
  res.status(200).end()
})



module.exports = router;
